﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Utility;
using BUS;

public partial class Administrator_deal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        pager.PageSize = 15;
        Criteria c = new Criteria();

        int total = 0;
        Tbl_Deal_Collection dealCollection =
            Tbl_Deal_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            Tbl_Deal_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = dealCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_Deal_Entities deal = (Tbl_Deal_Entities)e.Item.DataItem;
            HyperLink hyp_madeal = (HyperLink)e.Item.FindControl("hyp_madeal");
            HyperLink hyp_tensp = (HyperLink)e.Item.FindControl("hyp_tensp");
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");
            HyperLink hyp_loaisp = (HyperLink)e.Item.FindControl("hyp_loaisp");
            HyperLink hyp_doanhnghiep = (HyperLink)e.Item.FindControl("hyp_doanhnghiep");
            Literal lit_ngayban = (Literal)e.Item.FindControl("lit_ngayban");

            Tbl_sanpham_Entities sp = Tbl_sanpham_BUS.GetByID(deal.STT_sanpham);
            hyp_tensp.NavigateUrl = "~/Administrator/sanpham.aspx?idsanpham=" + deal.STT_sanpham;
            hyp_tensp.Text = sp.TenSP;

            Tbl_doanhnghiep_Entities dn = Tbl_doanhnghiep_BUS.GetByID(sp.STT_doanhnghiep);
            hyp_doanhnghiep.NavigateUrl = "~/Administrator/doanhnghiep_chitiet.aspx?id=" + sp.STT_doanhnghiep;
            hyp_doanhnghiep.Text = dn.TenDoanhNghiep;

            Tbl_loaisp_Entities lsp = Tbl_loaisp_BUS.GetByID(sp.LoaiSP);
            hyp_loaisp.NavigateUrl = "~/Administrator/loaisp.aspx?idloaisp=" + sp.LoaiSP;
            hyp_loaisp.Text = lsp.TenLoai ;

            hyp_madeal.NavigateUrl = "~/Administrator/dathang.aspx?iddh=" + deal.STT.ToString();
            lit_ngayban.Text = deal.NgayBan;
            lit_stt.Text = deal.STT.ToString();
        }
    }
}
